-
Notifications
You must be signed in to change notification settings - Fork 460
Minor cleanup from if
to guard
statement
#3172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@swift-ci Please test |
@swift-ci Please test macOS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I find if !self.at(.atSign)
easier and generally just use guard for introducing new variables, but 🤷
Sources/SwiftParser/Lookahead.swift
Outdated
|
||
// If we don't have attributes, then it cannot be an accessor block. | ||
if nextToken.rawTokenKind != .atSign { | ||
guard self.at(.atSign) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, nextToken
is peek()
. This is a behavior change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, I guess this shows why at
and peek(isAt:)
are more explicit. Added a test case for this.
get | ||
var x: Int = 2 | ||
{ | ||
@something |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rintaro Do you have an idea what kind of attribute would make sense here, I can’t think of anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's valid attribute for will/didSet
at this point, at least I couldn't find a test case in swift repo. I believe handling attributes here is mostly for recovery/diagnostics. So @something
is fine for me, maybe an attribute with argument clause (e.g. @available(...)
) in addition to that, for extra coverage.
func testAccessorBlockAfterPatternBindingDeclWithAttribute() { | ||
assertParse( | ||
""" | ||
var x: Int = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid literal here. We don't try parsing trailing closure for literals
swift-syntax/Sources/SwiftParser/Expressions.swift
Lines 936 to 937 in 06f123a
self.at(.leftBrace) && !leadingExpr.raw.kind.isLiteral | |
&& self.withLookahead({ $0.atValidTrailingClosure(flavor: flavor) }) |
I think the guard is a lot easier to read here, noticed while reviewing swiftlang#3171.
@swift-ci Please test |
@swift-ci Please test Windows |
I think the guard is a lot easier to read here, noticed while reviewing #3171.